﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using NewsPortal.DataContracts;
using NewsPortal.Linq;
using NewsPortal.Models;

namespace NewsPortal.Controllers
{
    public class ImageController : Controller
    {
        //
        // GET: /Image/

        public void ViewImage(string id,bool small)
        {
            Guid guid = new Guid(id);
            var connection = new Storage.MongoDbStorageProxy();
            Storage.Entity image = null;
            try
            {
                image = connection.Read(guid);
            }
            catch (Storage.EntityNotFoundException)
            {
                Response.Close();
                return;                
            }            
            Response.ContentType = "image/jpeg";
            Response.BinaryWrite(small ? image.Thumbnail : image.Body);
            
        }

        public ActionResult Index()
        {
            return RedirectToRoute("Default");
        }
    }
}
